package com.sparsearr.datastructures.ztr.recursion;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/5/14 19:36
 * @Description: 递归调用
 * @Version: 1.0
 */

public class RecursionTest {
    private static final Logger logger = LogManager.getLogger(RecursionTest.class);

    public static void main(String[] args) {
        test(4);

        int res = factorial(2);
        logger.info("阶乘~ res = {}", res);
    }

    public static void test(int n) {
        if (n > 2){
            test(n - 1);
        }
        logger.info("递归~ n = {}", n);
    }

    public static int factorial(int n){
        if (n == 1){
            return 1;
        } else {
            return factorial(n - 1) * n;
        }
    }
}
